﻿
@{
    ViewData["Title"] = "BackBecomeView";
    Layout = null;
}

<link href="~/Content/bootstrap-theme.css" rel="stylesheet"/>
<link href="~/layui/css/layui.css" rel="stylesheet"/>
<link href="~/layer/skin/layer.css" rel="stylesheet"/>

<form class="layui-form" action="">
    <div style="width: 600px">
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span> 部  门：</label>
            <div class="layui-input-block">
                <select id="Department" name="Department" lay-verify="required" lay-reqText="请选择部门"  lay-filter="Department">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span> 职  位：</label>
            <div class="layui-input-block">
                <select id="Position" name="Position" lay-verify="required"  lay-reqText="请选择职位">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span> 员工姓名:</label>
            <div class="layui-input-block">
                <select id="Staff" name="Staff" lay-verify="required" lay-reqText="请选择员工姓名" >
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span> 上级负责人：</label>
            <div class="layui-input-block">
                <select id="Superior" name="Superior" lay-verify="required" lay-reqText="请选择上级联系人">
                    <option value="">请选择上级负责人</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>  入职日期：</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="Bdate" lay-reqText="请选择入职时间">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>  申请时间：</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="Bdatetime" lay-reqText="请选择申请时间">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span> 试用期工作总结：：</label>
            <div class="layui-input-block">
                <textarea id="Bsum" name="Bsum" placeholder="请填写试用期工作总结" class="layui-textarea" >无</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span> 对公司的意见和建议：：</label>
            <div class="layui-input-block">
                <textarea id="Bopinion" name="Bopinion" placeholder="请填写对公司的意见和建议" class="layui-textarea" >无</textarea>
            </div>
        </div>
    </div>
</form>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn layui-btn-normal" onclick="AddInfo()">提交审核</button>
        <button class="layui-btn layui-btn-primary" onclick="location.href ='/PersonnelMatters/BecomeARegularWorkerView'">取消</button>
    </div>
</div>


<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script src="~/layui/layui.js"></script>
<script src="~/layer/layer.js"></script>
<script>

    var id = @ViewBag.id;

    $(function() {
        //Demo
        layui.use(['form', 'laydate'],
            function() {
                form = layui.form;
                var laydate = layui.laydate;
                laydate.render({
                    elem: '#EntryDate' //指定元素
                });
            });
        Back();
        GetDeptinfoList();
    });
    function renderTime(date) {
        var dateee = new Date(date).toJSON();
        return new Date(+new Date(dateee) + 8 * 3600).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '');
    }

    function Back() {
        $.ajax({
            url: "/PersonnelMatters/GetBecomeData?id=" + id+"&state="+2,
            type: "get",
            success: function(obj) {
                $("#Department").val(obj.did);
                GetPositionInfoList();
                $("#Position").val(obj.tid);
                Staff();
                $("#Staff").val(obj.xid);
                $("#Superior").val(obj.uid);
                $("#Bdate").val(renderTime(obj.bdate));
                $("#Bdatetime").val(renderTime(obj.bdatetime));
                $("#Bsum").val(obj.bsum);
                $("#Bopinion").val(obj.bopinion);
            }
        });
    }

    function AddInfo() {
        var data = {
            Xid: $("#Staff").val(),
            Did: $("#Department").val(),
            Tid: $("#Position").val(),
            Uid: $("#Superior").val(),
            Bdate: $("#Bdate").val(),
            Bdatetime: $("#Bdatetime").val(),
            Bsum: $("#Bsum").val(),
            Bopinion: $("#Bopinion").val()
        }
        if (data.Xid === 0) {
            layer.msg("请选择员工");
        }
        if (data.Did === 0) {
            layer.msg("请选择部门");
        }
        if (data.Tid === 0) {
            layer.msg("请选择职位");
        }
        if (data.Uid === 0) {
            layer.msg("请选择上级负责人");
        } 
        if (data.Bdate === null) {
            layer.msg("请选择入职时间");
        }
        if (data.Bdatetime === null) {
            layer.msg("请选择最后工作时间");
        }
        console.log(data);
        $.ajax({
            url: "/PersonnelMatters/AddBecomeData",
            type: "post",
            data: data,
            success: function(obj) {
                if (obj > 0) {
                    layer.alert('修改成功！');
                } else {
                    layer.alert('修改失败');
                }
            }
        });
    }
    //通过部门获取
    function Staff() {
        var id = $("#Department").val();
        $("#Staff").empty();
        $("#Superior").empty();
        $.get("/PersonnelMatters/GetBasicByDepId?depId=" + id,
            function(res) {
                var str = '<option value="0">请选择员工姓名</option>';
                var str1 = '<option value="0">请选择上级负责人</option>';
                res.forEach(a => {
                    str += (' <option value="' + a.id + '">' + a.name + '</option>');
                    str1 += (' <option value="' + a.id + '">' + a.name + '</option>');
                });
                $("#Staff").append(str);
                $("#Superior").append(str1);
                form.render('select');
            });
    }

    //获取部门集合
    function GetDeptinfoList() {
        $.get("/PersonnelMatters/GetDeptinfoList",
            function(res) {
                var str = '<option value="0">请选择一个部门</option>';
                res.forEach(a => {
                    str += (' <option value="' + a.id + '">' + a.name + '</option>');
                });
                $("#Department").append(str);
            });
        GetPositionInfoList();
    }

    //获取职业集合
    function GetPositionInfoList() {
        var id = $("#Department").val();
        $("#Position").empty();
        $.get("/PersonnelMatters/GetPositionInfoList?id=" + id,
            function(res) {
                var str = '<option value="0">请选择一个职位</option>';
                res.forEach(a => {
                    str += (' <option value="' + a.id + '">' + a.name + '</option>');
                });
                $("#Position").append(str);
                form.render('select');
            });
    }
</script>


